
# -*- coding: utf-8 -*-
import sys
import numpy as np
import matplotlib.pyplot as plt
import math
 
# 加载图片的名称
pathname = '/Users/weishoufeng/Desktop/test4.png'
# Mac下用GIMP查看坐标，注意下面提到的坐标顺序是[y, x]，windows下系统自带画图似乎就可以
# 起始像素点坐标（左上角）
start_points = [26, 80]
# 结束像素点点坐标（右下角）
end_points = [238, 995]
# 要显示曲线的像素点的y的坐标范围（从上到下）
pivot_ys = [36, 238]
# 要显示曲线的y的真实坐标范围（从上到下）
pivot_metrics = [100, 0]
# 曲线的颜色RGB
line_color = np.asarray([0., 231., 0.])
img = None
try:
	# pip install opencv-python
    import cv2
    img = cv2.imread(pathname)
    # cv2颜色的顺序是GBR
    line_color = [line_color[2], line_color[1], line_color[0]]
except ImportError:
    print ('cv2 modular not found!')
 
if img is None :
    try:
        from PIL import Image
        img = np.array(Image.open(pathname))
    except ImportError:
        print ('PIL modular not found!')
 
if img is None :
    print ('PIL or cv2 not found!')
    sys.exit()
 
ratio = (pivot_metrics[1] - pivot_metrics[0] + 0.0) / (pivot_ys[1] - pivot_ys[0] + 0.0) #0.0的作用是转化为float型
 
cand = {}
 
min_c = 100000
max_c = -1
 
temp = {}
for r in range(start_points[0], end_points[0]):
    for c in range(start_points[1], end_points[1]):
        rgb = img[r,c][0:3]
        a = math.sqrt(math.pow(rgb[0]-line_color[0],2)+math.pow(rgb[1]-line_color[1],2)+math.pow(rgb[1]-line_color[1],2))
        if a< 100:
        	print("%d,%d"%(c,r))

